Debian: How to get the original "/etc/apt/sources.list" file? (if is possible)

Hello Friends

For Debian 12 and 13. Consider any of the following scenarios:

  • The /etc/apt/sources.list.bak file never was created
  • The /etc/apt/sources.list.bak file was deleted by error

Question

  • How to get the original /etc/apt/sources.list file? (if is possible)

Even if the /etc/apt/sources.list.bak file exists yet is possible retrieve/get the original file to a custom filename?

I mean something like:

Therefore to have in the /etc/apt/ directory the following files (among others)

Thanks in advance

2 Likes

I did a quick search and it looks like the original should be here:
/usr/share/base-files/sources.list

6 Likes

Use a live usb drive. Copy its sources.list to your internal drive.

5 Likes

Huge thanks to both for the replies

pdecker

I did a quick search and it looks like the original should be here:
/usr/share/base-files/sources.list

Understood, let me confirm it. BTW What is your name?

Neville

Use a live usb drive. Copy its sources.list to your internal drive.

Has sense, I am assuming is possible mount the SSD into the ā€œLiveā€, Am I correct? Is is always safe? If it would have any kind of risk I would use the LAN to send the copy of the file

1 Like

I dont see any risk doing that.
I often do that when I want to fix a linux that will not boot.

2 Likes

Interesting scenario, why happen that? How common happens?

1 Like

For example if you move a linux to another partition, it will not boot. You need to edit /etc/fstab and change the uuid’s. You also may need to edit /etc/grub.cfg

It is also fairly common for people to edit /etc/fstab and get it wrong. The way to fix it is to boot another linux, mount the root filesystem of the dud linux, and fix fstab.

People used to use knoppix for this… but any live distro will do.

5 Likes

Yeah - happened to me quite a few times…

On most later distros - you can boot what we’d call in Solaris ā€œSingle User Modeā€ - or ā€œRescueā€ mode, from GRUB… and in the rescue environment, you setup a chroot, mount ā€œ/ā€ and edit e.g. vi /mnt/chroot/etc/fstab ). Not going to cover setting up a chroot here - anyone interested can google/duckduck/copilot/bing it…

I ALWAYS make a backup of /etc/fstab if I’m going to manually edit it… it’s so easy :

sudo cp /etc/fstab /etc/fstab.bkup.$(date '+%Y%m%d')

and an even more efficient single command :

sudo cp /etc/fstab{,.bkup.$(date '+%Y%m%d')}

5 Likes

Very important… especially in the old days when single user mode only had a line editor.

2 Likes

There are those who call me, Tim. :wink:

3 Likes

Back then - you’d have had to use backticks to quote an executable in a variable anyway :smiley:

cp /etc/fstab /etc/fstab.bkup.`date '+%Y%m%d'`

Never mind ā€œchainingā€ commands in braces with a comma…

And probably not even sudo - just plain old root :smiley: … My only experience with such systems was Solaris - using a serial terminal multiplexer as system console - and yeah - vi was pretty much unusable…

3 Likes

It was not there… I think single user only had /bin and vi was in /usr/bin.

Vi was OK on a serial terminal… I have even used it via a 1200 baud modem.

1 Like

As usual thanks for the replies

Neville

For example if you move a linux to another partition, it will not boot. You need to edit /etc/fstab and change the uuid’s. You also may need to edit /etc/grub.cfg

Thanks to do mention for this scenario … now, why is need do that?.

It is also fairly common for people to edit /etc/fstab and get it wrong. The way to fix it is to boot another linux, mount the root filesystem of the dud linux, and fix fstab.

Understood

People used to use knoppix for this… but any live distro will do.

Thanks for the mention of that tool. Is this one?

Dan

I ALWAYS make a backup of /etc/fstab if I’m going to manually edit it… it’s so easy :
sudo cp /etc/fstab /etc/fstab.bkup.(date '+%Y%m%d') and an even more efficient single command : sudo cp /etc/fstab{,.bkup.(date ā€˜+%Y%m%d’)}

Thanks for that valuable feedback

1 Like

Yes, that is the genuine Knoppix live system.
It was the pioneer of live systems.
It contains various tools useful in recovery or patching a system.

1 Like

I have a vague memory - circa 10+ years ago of having a ā€œhosedā€ (garbage) /etc/apt/sources.list file on a Debian Jessie system…

I did a fairly basic google search and got a ā€œGenericā€ sorta ā€œdefaultā€ Debian Jessie sources.list file… They’re out there… Which solved that issue…

They’d only vary if e.g. you edited yours to use a closer mirror - which makes sense, but there-in lies the danger - one wrong edit and you’re stuffed, up sh!t creek in a barbed wire canoe!

I’ve also seen (experienced ā€œfirst handā€) issues where Debian refused to update - and I ended up editing the sources.list file - instead of double-checking DNS…

Yeah - it was a DNS issue… It’s nearly always DNS :smiley: :

3 Likes