# [solved] / on ext4 suddenly gets mounted ro

## Elleni

On a recently installed gentoo, I have the problem that it mounts /dev/sda3 -> / read only. That started occuring all of a sudden. I dont see why. I am able to remount rw after login. 

Furthermore, I realized that keymaps is defaulting to us, in local login with locally attached keyboard despite having set 

keymaps to de_CH-latin1. 

When I access the box via ssh, I have the correct keymaps. 

I dont see anyting obvious in dmesg: 

https://bpaste.net/show/81d662efbbbb

fstab only containing the bare minimum: 

```
/dev/sda1               /boot           ext2            noauto,noatime          1 2

/dev/sda3               /               ext4            noatime,discard         0 1

/dev/sda2               none            swap            sw,discard              0 0
```

emerge --info

```

Portage 2.3.62 (python 3.6.5-final-0, default/linux/amd64/17.0/desktop/plasma, gcc-8.2.0, glibc-2.28-r6, 4.19.27-gentoo-r1 x86_64)

=================================================================

System uname: Linux-4.19.27-gentoo-r1-x86_64-Intel-R-_Core-TM-_i7-4790S_CPU_@_3.20GHz-with-gentoo-2.6

KiB Mem:     8121292 total,   5807940 free

KiB Swap:          0 total,         0 free

Timestamp of repository gentoo: Sat, 04 May 2019 08:30:01 +0000

Head commit of repository gentoo: f4dd38f04012aa375114a3494566773c2bb9af8a

sh bash 4.4_p23-r1

ld GNU ld (Gentoo 2.31.1 p5) 2.31.1

app-shells/bash:          4.4_p23-r1::gentoo

dev-java/java-config:     2.2.0-r4::gentoo

dev-lang/perl:            5.26.2::gentoo

dev-lang/python:          2.7.15::gentoo, 3.6.5::gentoo

dev-util/cmake:           3.9.6::gentoo

sys-apps/baselayout:      2.6-r1::gentoo

sys-apps/openrc:          0.29::dantrell-gnome

sys-apps/sandbox:         2.13::gentoo

sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r4::gentoo

sys-devel/automake:       1.11.6-r3::gentoo, 1.16.1-r1::gentoo

sys-devel/binutils:       2.31.1-r4::gentoo

sys-devel/gcc:            8.2.0-r6::gentoo

sys-devel/gcc-config:     2.0::gentoo

sys-devel/libtool:        2.4.6-r3::gentoo

sys-devel/make:           4.2.1-r4::gentoo

sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)

sys-libs/glibc:           2.28-r6::gentoo

Repositories:

gentoo

    location: /usr/portage

    sync-type: rsync

    sync-uri: rsync://rsync.gentoo.org/gentoo-portage

    priority: -1000

    sync-rsync-verify-jobs: 1

    sync-rsync-extra-opts: 

    sync-rsync-verify-metamanifest: yes

    sync-rsync-verify-max-age: 24

x-portage

    location: /usr/local/portage

    masters: gentoo

    priority: 0

dantrell-gnome-3-32

    location: /var/lib/layman/dantrell-gnome-3-32

    masters: gentoo

    priority: 100

dantrell-gnome

    location: /var/lib/layman/dantrell-gnome

    masters: gentoo

    priority: 150

ACCEPT_KEYWORDS="amd64"

ACCEPT_LICENSE="* -@EULA"

CBUILD="x86_64-pc-linux-gnu"

CFLAGS="-march=native -O2 -pipe"

CHOST="x86_64-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt"

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"

CXXFLAGS="-march=native -O2 -pipe"

DISTDIR="/usr/portage/distfiles"

ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"

FCFLAGS="-march=native -O2 -pipe"

FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg candy config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"

FFLAGS="-march=native -O2 -pipe"

GENTOO_MIRRORS="http://distfiles.gentoo.org"

LANG="de_CH.UTF-8"

LDFLAGS="-Wl,-O1 -Wl,--as-needed"

LINGUAS="de de_DE"

MAKEOPTS="-j9"

PKGDIR="/usr/portage/packages"

PORTAGE_CONFIGROOT="/"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"

PORTAGE_TMPDIR="/var/tmp"

USE="X a52 aac acl acpi activities aes alsa amd64 avx avx2 berkdb bluetooth branding bzip2 cairo cdda cdr cli colord crypt cups cxx dbus declarative dri dts dvd dvdr eds egl elogind emboss encode evo exif f16c fam ffmpeg flac fma3 fortran gdbm gif glamor gles gnome gnome-keyring gnome-online-accounts gnutls gpm grub gtk gtk3 gtkstyle iconv introspection ipv6 jpeg kde kipi kwallet lcms ldap libnotify libsecret libtirpc lm_sensors mad mmx mmxext mng mp3 mp4 mpeg multilib nautilus ncurses nls nptl ocr ogg opengl openmp osmesa pam pango pclmul pcre pdf phonon plasma png policykit popcnt ppds pulseaudio qml qt5 rdp readline realtime s3tc scanner sdl seccomp semantic-desktop sna spell spice sse sse2 sse3 sse4_1 sse4_2 ssl ssse3 staging startup-notification svg tcpd theora tiff tracker truetype udev udisks unicode upower usb vaapi vdpau vhost-net vkd3d vnc vorbis vpx vulkan wayland webrtc-aec widgets wxwidgets x264 xattr xcb xcomposite xml xv xvid zlib" ABI_X86="64 32" ALSA_CARDS="hda-intel" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssh ssl ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="evdev" KERNEL="linux" L10N="de" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" NETBEANS_MODULES="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6 php7-1" POSTGRES_TARGETS="postgres9_5 postgres10" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_6" QEMU_SOFTMMU_TARGETS="i386 x86_64" QEMU_USER_TARGETS="i386 x86_64" RUBY_TARGETS="ruby24" SANE_BACKENDS="pixma" USERLAND="GNU" VIDEO_CARDS="intel i965 virgl" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"

Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
```

What I was doing before this started happening: 

I had installed plasma thus using 17.0 plasma profile. That worked quite well, there was only one issue, that sddm did not launch and switch to tty7 automatically, although it has been added to default runlevel, but only after hitting enter or some other random keystrokes on a locally attached keyboard. 

I then emerged haveged as suggested by asturm but had not put it into any runlevel, so obviously it did not solve the sddm problem. In the meantime I wanted to try dantrells gnome without systemd and with it its gdm, and so I followed the instructions to set this up: 

- Add overlays

- modify make.conf

```
# These settings were set by the catalyst build script that automatically

# built this stage.

# Please consult /usr/share/portage/config/make.conf.example for a more

# detailed example.

COMMON_FLAGS="-march=native -O2 -pipe"

CFLAGS="${COMMON_FLAGS}"

CXXFLAGS="${COMMON_FLAGS}"

FCFLAGS="${COMMON_FLAGS}"

FFLAGS="${COMMON_FLAGS}"

# WARNING: Changing your CHOST is not something that should be done lightly.

# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.

CHOST="x86_64-pc-linux-gnu"

CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssh ssl ssse3"

USE="aes avx avx2 bluetooth dri f16c ffmpeg fma3 gles gnutls grub -libav lm_sensors mmx mmxext ocr pclmul popcnt pulseaudio osmesa sna sse sse2 sse3 sse4_1 sse4_2 ssse3 rdp realtime s3tc scanner spice staging t$

# dantrell gnome without systemd

USE="${USE} -ck elogind"

USE="${USE} egl wayland"

ABI_X86="64 32"

ACCEPT_KEYWORDS="amd64"

# NOTE: This stage was built with the bindist Use flag enabled

PORTDIR="/usr/portage"

DISTDIR="${PORTDIR}/distfiles"

PKGDIR="${PORTDIR}/packages"

MAKEOPTS="-j9"

VIDEO_CARDS="intel i965 virgl"

ALSA_CARDS="hda-intel"

INPUT_DEVICES="evdev"

LINGUAS="de de_DE"

L10N="de"

# FEATURES="candy clean-logs"

#FEATURES="candy"

FEATURES="buildpkg candy -collision-protect -protect-owned -xattr"

SANE_BACKENDS="pixma"

PORTDIR_OVERLAY=/usr/local/portage

# XFCE_PLUGINS="clock power multiload-nandhp trash"

# PORTAGE_TMPDIR="/tmp"

# EMERGE_DEFAULT_OPTS="--quiet-build=y"

# PORT_LOGDIR="/var/log/portage"

# EMERGE_DEFAULT_OPTS="--with-bdeps=y --jobs=3 --load-average=2"

QEMU_USER_TARGETS="i386 x86_64" 

QEMU_SOFTMMU_TARGETS="i386 x86_64"

MICROCODE_SIGNATURES="-s 0x000306c3"

# This sets the language of build output to English.

# Please keep this setting intact when reporting bugs.

LC_MESSAGES=C
```

- select profile  ([47]  dantrell-gnome:default/linux/amd64/17.0/desktop/gnome+plasma (stable) *)

emerge world -uDNav - which finished successfully. But I had to re-emerge glibc and gtk+

As said, I can remount,rw / and having mounted / read only, I checked with fscheck.ext4 but it said, it is clean. 

And here s the kernel config file, just in case that matters: 

https://bpaste.net/show/3355ec1710b6

What can I do to solve this?

At the moment I am not sure, wether I should revert back to gentoo 17.0 standard profile without dantrells gnome to see if that restores normal behaviour or - and thats what I am doing right now, proceed with the installation of gnome by issuing 

```
emerge gnome gnome-extra-apps
```

 and see what happens once everything has been emerged correctly. 

Having installed plasma and gnome without systemd on my main box, I dont see this being the source of the problem, as it is working fine on my main box. 

Thanks in advance for any help that could lead me to the right direction.Last edited by Elleni on Wed May 08, 2019 8:08 pm; edited 1 time in total

----------

## NeddySeagoon

Elleni,

A filesystem goes read only in response to errors.

At boot, root is checked but as its mounted read only for the check, only limited repairs are possible.

dmesg may contain IO errors. That's a bad sign.

The SMART data for the drive would be good to see. You may have a failing drive. 

Run 

```
smartctl -a /dev/<drive>
```

smartctl is provided by smartmontools.

Do not run fsck unless you have validated backups. It can make things much worse, not better.

----------

## Elleni

Hi NeddySeagoon, 

Did you see I/O errors on above attached dmesg ?

I run fsck.ext with -n just for information and to be sure it will not corrupt data, but thanks for the pointer  :Smile: 

LC_ALL=C fsck.ext4 -nvf /dev/sda3

```
e2fsck 1.44.5 (15-Dec-2018)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

      635183 inodes used (4.21%, out of 15089664)

         419 non-contiguous files (0.1%)

         264 non-contiguous directories (0.0%)

             # of inodes with ind/dind/tind blocks: 0/0/0

             Extent depth histogram: 610463/45

     6891857 blocks used (11.42%, out of 60353366)

           0 bad blocks

           1 large file

      554268 regular files

       55633 directories

         174 character device files

          97 block device files

           4 fifos

         356 links

       24996 symbolic links (24390 fast symbolic links)

           2 sockets

------------

      635530 files
```

here is the output of smartctl -a /dev/sda

```
smartctl -a /dev/sda

smartctl 7.0 2018-12-30 r4883 [x86_64-linux-4.19.27-gentoo-r1] (local build)

Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===

Device Model:     SanDisk SD7TB3Q-256G-1006

Serial Number:    154408401721

LU WWN Device Id: 5 001b44 eff0a3739

Firmware Version: X2180306

User Capacity:    256'060'514'304 bytes [256 GB]

Sector Sizes:     512 bytes logical, 4096 bytes physical

Rotation Rate:    Solid State Device

Form Factor:      2.5 inches

Device is:        Not in smartctl database [for details use: -P showall]

ATA Version is:   ACS-2 T13/2015-D revision 3

SATA Version is:  SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)

Local Time is:    Mon May  6 00:18:09 2019 CEST

SMART support is: Available - device has SMART capability.

SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===

SMART overall-health self-assessment test result: PASSED

See vendor-specific Attribute list for marginal Attributes.

General SMART Values:

Offline data collection status:  (0x82)   Offline data collection activity

               was completed without error.

               Auto Offline Data Collection: Enabled.

Self-test execution status:      (   0)   The previous self-test routine completed

               without error or no self-test has ever 

               been run.

Total time to complete Offline 

data collection:       (  120) seconds.

Offline data collection

capabilities:           (0x5b) SMART execute Offline immediate.

               Auto Offline data collection on/off support.

               Suspend Offline collection upon new

               command.

               Offline surface scan supported.

               Self-test supported.

               No Conveyance Self-test supported.

               Selective Self-test supported.

SMART capabilities:            (0x0003)   Saves SMART data before entering

               power-saving mode.

               Supports SMART auto save timer.

Error logging capability:        (0x01)   Error logging supported.

               General Purpose Logging supported.

Short self-test routine 

recommended polling time:     (   2) minutes.

Extended self-test routine

recommended polling time:     (  17) minutes.

SCT capabilities:           (0x003d)   SCT Status supported.

               SCT Error Recovery Control supported.

               SCT Feature Control supported.

               SCT Data Table supported.

SMART Attributes Data Structure revision number: 16

Vendor Specific SMART Attributes with Thresholds:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE

  1 Raw_Read_Error_Rate     0x002f   252   252   002    Pre-fail  Always       -       0

  5 Reallocated_Sector_Ct   0x0033   252   252   005    Pre-fail  Always       -       0

  9 Power_On_Hours          0x0032   252   252   ---    Old_age   Always       -       190

 12 Power_Cycle_Count       0x0032   252   252   ---    Old_age   Always       -       132

170 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0

171 Unknown_Attribute       0x0022   100   100   ---    Old_age   Always       -       0

172 Unknown_Attribute       0x0032   100   100   ---    Old_age   Always       -       0

173 Unknown_Attribute       0x0033   100   100   005    Pre-fail  Always       -       34362228738

174 Unknown_Attribute       0x0032   252   252   ---    Old_age   Always       -       36

183 Runtime_Bad_Block       0x0032   100   100   000    Old_age   Always       -       0

184 End-to-End_Error        0x0033   100   100   097    Pre-fail  Always       -       0

187 Reported_Uncorrect      0x0032   100   100   ---    Old_age   Always       -       0

188 Command_Timeout         0x0032   100   099   ---    Old_age   Always       -       2

190 Airflow_Temperature_Cel 0x0022   061   031   045    Old_age   Always   In_the_past 39

196 Reallocated_Event_Count 0x0032   252   252   ---    Old_age   Always       -       0

199 UDMA_CRC_Error_Count    0x0022   100   100   ---    Old_age   Always       -       0

244 Unknown_Attribute       0x0032   000   100   ---    Old_age   Always       -       0

SMART Error Log Version: 1

No Errors Logged

SMART Self-test log structure revision number 1

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error

# 1  Short offline       Completed without error       00%         0         -

SMART Selective self-test log data structure revision number 1

 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS

    1        0        0  Not_testing

    2        0        0  Not_testing

    3        0        0  Not_testing

    4        0        0  Not_testing

    5        0        0  Not_testing

Selective self-test flags (0x0):

  After scanning selected spans, do NOT read-scan remainder of disk.

If Selective self-test is pending on power-up, resume after 0 minute delay.
```

This is what is shown in tty1

https://pasteboard.co/Idm1BFC.jpg

but I guess thats because of / beeing mounted readonly

----------

## NeddySeagoon

Elleni,

All that looks good.  Faulty SATA data cables can produce apparent filesysytem errors.

----------

## Elleni

At the moment I am doing an emerge -eav world to see if that helps. 

As I have a second identical box I will afterwards just put the harddisk in the other box and see, how it behaves. Thanks for looking into it. Or maybe I should just connect to both via ssh transfer the whole installation to the second box? How would I do this preserving file permissions and everything? I probably ideally boot both boxes with a livemedium, right?

Now that I think of it, I also played a bit with bios settings. Particullary I activated virtualisation options that would be needed for kvm; maybe I should revert them back and/or restore bios to default settings to see if that could resolve the issue?Last edited by Elleni on Mon May 06, 2019 12:34 am; edited 2 times in total

----------

## Hu

According to that output, the drive ran one short selftest when it was new, but has never run a user-requested long test.  The drive is still quite young, but at some point you should probably run smartctl --test=long on it.  Plan to leave it powered up for at least 17 minutes afterward, then check the output of smartctl -a.  For such a young drive, I doubt you will find anything that way this time, but it's a good habit to run the self-test once a month or so.

----------

## Elleni

Hi Hu, thanks for your post. I ll do as suggested, but as its late here and I just started emptytree world rebuild, I will check this after it rebuilt everything. And as having the opportunity of having one more identical box - I would like to try what happens on the other hardware. I can try to just put the harddrive in the second box to see if it boots correctly there or - as soon as I find out how to clone the entire disk including file permissions - transfer the whole install on the other identical disk and see what happens.Last edited by Elleni on Mon May 06, 2019 8:06 am; edited 1 time in total

----------

## Elleni

I decided to go back to gentoo kdeplasma with openrc profile 17.0 and unmerge everything overlay related to see if the problem will persist. I will post here, what fails during emerge -eav system && emerge -eav world in the hope I will get help to solve any upcoming failures. I suppose - like this I'll be having everything reset to standard. 

As pambase complained, I had to put elogind useflag for pambase in package.use to be able to issue emerge -eav system: 

With consolekit useflag (comming from plasma profile) only, pambase asked for elogind. 

Or should I bether add -consolekit elogind in make.conf? What would be the correct setting ?

When I tried adding elogind in make.conf and with consolekit enabled comming from the profile, polkit complained to use just one of: consolekit, elogind, systemd. 

```
WARNING: One or more updates/rebuilds have been skipped due to a dependency conflict:

sys-auth/pambase:0

  (sys-auth/pambase-20150213-r2:0/0::gentoo, ebuild scheduled for merge) conflicts with

    sys-auth/pambase[elogind] required by (kde-plasma/plasma-meta-5.14.5:5/5::gentoo, installed)

                     ^^^^^^^ 

    sys-auth/pambase[elogind] required by (x11-base/xorg-server-1.20.4:0/1.20.4::gentoo, installed)

                     ^^^^^^^ 

```

----------

## NeddySeagoon

Elleni,

consolekit is going away in favour of elogind.

Put elogind in make.conf and use consolekit  on a package by package basis as you must.

Just for the transition period. 

Eventually the per package consolekit settings will become redundant as consolekit will have been removed.

----------

## Elleni

After an emerge -e system sda3 was again mounting normally rw. I will remove consolekit in favour to elogind as you suggested. Don't know what caused this. But anyway, I am happy it works now. I will probably still try to clone the system to a second box. I know, I should boot source and destination box from a live medium but what would be the best way to transfer the whole disk preserving file permissions to the second box?

I will also proceed once again trying to add dantrell's gnome once more, as sddm does not like my box and stops with a black screen with a mouse; I hope gdm will behave better.

----------

## Elleni

I can reproduce the issue by again adding dantrells overlay and emerging gnome. I will now again issue an emerge -e system but this time without removing installed gnome and gnome-extra packages to see if it gets solved that way too, or if not, I will ask in his support thread for further assistance. The only other thing I have done, is to put -consolekit +elogind globally in make.conf and emerging world -uDNav.

----------

## Elleni

Thanks to dantrell I found out, that it was openrc version, I had installed that caused this. Every version below 0.41 in tree mounts / readonly on this box. Only 41.1 and 41.2 do mount rw. I don't understand it, as on my main machine (amd ryzen based) this does not happen, although I have installed openrc-0.29 too, and although the same ahci kernel option is used on both boxes.Last edited by Elleni on Mon May 13, 2019 1:19 am; edited 2 times in total

----------

## Elleni

And to answer my above question - I remembered an old thread where khayyam answered my question about howto clone the new gentoo box.

----------

## Elleni

I created a backup using the following from a livemedium: 

```
# mount /dev/sda2 /mnt/gentoo

# mount /dev/sda1 /mnt/gentoo/boot

# mount /dev/sdb1 /mnt/my_external_usb_drive

# tar -jcvfp --xattrs /mnt/my_external_usb_drive/stage4-$(hostname)-$(date +%F).tar.bz2 /mnt/gentoo/
```

I had to slightly modify it meaning I had to put --xattrs before -jcvfp and I had to add * after /mnt/gentoo (else tar of the booted livemedium knoppix would complain and refuse to do its job)

After restoring the file to a similar box with 

```
# mount /dev/sda2 /mnt/gentoo

# mount /dev/sda1 /mnt/gentoo/boot

# mount /dev/sdb1 /mnt/my_external_usb_drive

# cd / && tar -jxvfp --xattrs /mnt/my_external_usb_drive/stage4-hostname-2017-02-05.tar.bz2
```

I discovered that I cannot chroot in as there is no /bin/bash in unpacked / mounted @/mnt/gentoo

That were the only errors I had got creating the file: 

```
tar: Entferne führende „/“ von Elementnamen

tar: /mnt/gentoo/home/natalie/.config/opera/oauc_pipe: Socket ignoriert

tar: /mnt/gentoo/home/natalie/.config/opera/oauc_pipe_r: Socket ignoriert

tar: Entferne führende „/“ von Zielen harter Verknüpfungen

tar: /mnt/gentoo/tmp/.ICE-unix/3514: Socket ignoriert

tar: /mnt/gentoo/tmp/.ICE-unix/4121: Socket ignoriert

tar: /mnt/gentoo/tmp/sddm-auth95aad288-908f-48d6-8bb2-341debeb2cff: Socket ignoriert
```

Does that mean that the file is corrupt somehow as /bin/bash is missing?

Would it work to unpack an stage3 first and then to unpack the created file over it, or should I make a new attempt to get everything needed thus recreating tar.bz2 file?

And what would the exact tar options be to get a full copy of the system including /bin/bash and everything else?Last edited by Elleni on Sun May 19, 2019 9:53 pm; edited 1 time in total

----------

## Elleni

The problem I had got while restoring initially, was the path inside the tar.bz2 file. It reads: 

mnt/gentoo/...

So I had tried to cd to root of livesystem and extract it from there. For some reason it worked partially but the mnt/gentoo/home... was not extracted to the mountpoint but to /ramdisk/mnt/gentoo/home... so ramdisk got filled at some point and not all of the tar.bz2 was extracted. 

Digging in internet I found --strip-components=2 from this post

https://serverfault.com/questions/330127/tar-remove-leading-directory-components-on-extraction

Which finally let me extract everything as needed to my /mnt/gentoo by cd /mnt/gentoo and extract from there. 

Its then when I realized that bin directory was not backuped at all, so I could not chroot /mnt/gentoo /bin/bash because it did not exist. I extracted .bin then from a stage3 tarball which let me successfully chroot. 

Now I am still unsure what else could not have been backuped to my tar.bz2. 

So the question remains. What would be the correct command to issue bootet from a livesystem to get everything properly packed in a nice tar.bz2 file?Last edited by Elleni on Sun May 19, 2019 9:56 pm; edited 3 times in total

----------

## NeddySeagoon

Elleni,

You are trying to create a stage4 tarball.  Now you know its called a stage4, google should help. If not. post back.

----------

## Elleni

Hi Neddy, 

I am aware of stage4. The reason, I had tried to do it by booting a livemedium was the discussion I had some time ago, as I had got problems with the restore of a file that I had created with old mkstage4.sh that I had found very long time ago. So this time I wanted to follow szatox advice by just booting a livemedium and tar the whole thing from there thus not needing all those exclusions. In fact I had done this in the past if I remember correctly and it worked like a charm; no /bin folder was missing. Apparently somewhere I must have made mistakes this time, resulting in missing bin folder and wrong path in the created tar.bz2 file. It also makes me worry that there are missing some more folders, not only dev. 

In the meantime I found this script that was posted 3 days ago, so maybe I should try this from a booted gentoo box I want to backup. Or as said, I would like to find out what my error was while I created the tar.bz2 as I think, maybe the advice of szatox is still correct to better create the backup while having booted from a livemedium.

----------

## Elleni

Pardon me to ask again but what would be the correct procedure to create a proper stage4 archive including /bin folder? Should this be done from livemedium or would that mentioned script be good enough to create a stage4 image from within booted environment?

----------

## szatox

Eleni, it's safer and easier to use tar on a system that is not running, so any live medium would be handy.

Another thing you could do is 'mount --bind' your root to another directory to break free of the mountpoints, and optionally mount --bind other persistend filesystems on top of that, and then tar that directory (excluding the archive itself, unless you can create it on another device that won't be covered by tar, or stream it to another machine). It would greatly reduce need for excludes on /dev, /proc, /sys/, /whoknowswhatelse

Note that an archive created from a booted system is not a strictly consistent. It will work in most cases, but it is likely to break e.g. databases if you have any. On a desktop machine, you probably don't, so it should be good enough.

Now, you mentioned problems with paths in the archive. Here's the trick: tar uses the source path you provide it with and embeds in the archive. And it will later attempt to extract your files to the same path. Once your directory tree is ready, cd into the filesystem root you wish to backup and invoke tar like this "tar cjf  /path/to/archive.tbz ."

That final dot says "put current working directory into that new archive".

Obviously, you can add more flags as you see fit. Once done, cd into the new filesystem and then extract your archive with "tar xf /path/to/archive.tbz"

System being booted or mounted does not affect tar's behaviour regarding including or excluding particular paths.

----------

## Elleni

Hi szatox, 

To create stage4 after having booted from a livemedium is exactly what khayyam had suggested two years ago, lately I tried to follow the given instructions you and khayyam have described. (Interesting additional option with mount by the way. Thanks  :Smile: ) But while restoring I had the mentioned path problem (thanks for your explanation) but furthermore I discovered that the bin folder was completely missing while I don't beleive I had it excluded. Unfortunately the original box was not available anymore so I could not re-create another archive. Fortunately I was able to workaround the problem by extracting bin from a downloaded stage3 archive. After all I have recompiled everything on the second box, so I am now sure, it is in a consistent state. Now that the new box is operational with added layer of lvm that the original box did not have, I will be able to retry to create an archive and see, it this time everything goes well and I'll have to check if the stage4 archive I will create, will be complete.

----------

